/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.view.baseDataView;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.event.ActionEvent;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;

import com.ruipengkj.ApplicationContext;
import com.ruipengkj.commons.util.SwingUtil;
import com.ruipengkj.commons.util.Util;
import com.ruipengkj.view.base.BaseInternalFrame;
import com.ruipengkj.view.memberView.CabinetPanel;
/**
 * 说明：
 * 基础数据管理主窗体
 * @Author：黄盛强
 * @Date：2012-03-20
 */
public class DataInternalFrame extends BaseInternalFrame {

	private static final long serialVersionUID = 1L;
	private JToolBar toolBar;//工具栏
	
	private JPanel main;//主面板
	private CardLayout main_layout;//主面板布局
	
	private JButton dataCommodityButton;//商品管理按钮
	private DataCommodityPanel dataCommodityPanel;//商品管理面板
	
	private JButton dataEmployeesButton;//员工管理按钮
	private DataEmployeesPanel dataEmployeesPanel;//员工管理面板
	
	private JButton dataStorageButton;//仓库管理按钮
	private DataStoragePanel dataStoragePanel;//仓库管理面板
	
	private JButton dataVendorButton;//供应商管理按钮
	private DataSupplierPanel dataVendorPanel;//供应商管理面板
	
	private JButton dataShopButton;//商店管理按钮
	private DataShopPanel dataShopPanel;//商店管理面板
	
	private JButton cabinetButton;//商柜管理按钮
	private CabinetPanel cabinetPanel;//商柜管理面板
	
	
	
	public DataInternalFrame(String title, boolean resizable, boolean closable,
			boolean maximizable, boolean iconifiable) {
		super(title, resizable, closable, maximizable, iconifiable);
		init();
	}

	private void init(){
		this.setLayout(new BorderLayout());
		this.initComponents();
		this.initListener();
	}
	
	//初始化组件
	private void initComponents() {
		toolBar = new JToolBar();
		toolBar.setFloatable(false);//设置工具栏不可移动
		dataCommodityButton=new JButton("商品管理",SwingUtil.getOpenSwingImage("commodity_manager.png"));
		dataEmployeesButton=new JButton("员工管理",SwingUtil.getOpenSwingImage("employees_manager.png"));
		dataStorageButton=new JButton("仓库管理",SwingUtil.getOpenSwingImage("store_manager.png"));
		dataVendorButton=new JButton("供应商管理",SwingUtil.getOpenSwingImage("suppliers_manager.png"));
		dataShopButton=new JButton("商店管理",SwingUtil.getOpenSwingImage("suppliers_manager.png"));
		cabinetButton=new JButton("商柜管理",SwingUtil.getOpenSwingImage("suppliers_manager.png"));
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL31)){
			toolBar.add(dataCommodityButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL32)){
			toolBar.add(dataEmployeesButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL33)){
			toolBar.add(dataStorageButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL34)){
			toolBar.add(dataVendorButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL36)){
			toolBar.add(cabinetButton);
		}
		toolBar.add(dataShopButton);
		main=new JPanel();
		main_layout=new CardLayout();
		main.setLayout(main_layout);
		
		this.add(toolBar,BorderLayout.NORTH);
		this.add(main,BorderLayout.CENTER);
	}
	//初始化监听器
	private void initListener() {
		dataCommodityButton.addActionListener(this);
		dataEmployeesButton.addActionListener(this);
		dataStorageButton.addActionListener(this);
		dataVendorButton.addActionListener(this);
		dataShopButton.addActionListener(this);
		cabinetButton.addActionListener(this);
	}
	
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==dataCommodityButton){
			//商品管理按钮
			dataCommodityPanel = new DataCommodityPanel();
			main.add(dataCommodityPanel,"dataCommodityPanel");
			main_layout.show(main, "dataCommodityPanel");
			this.setTitle("基础数据管理--商品管理");
			Util.setButtonStatus(toolBar,dataCommodityButton);
			SwingUtilities.invokeLater(dataCommodityPanel);
		}else if(e.getSource()==dataEmployeesButton){
			//员工管理按钮
			dataEmployeesPanel = new DataEmployeesPanel();
			main.add(dataEmployeesPanel,"dataEmployeesPanel");
			main_layout.show(main, "dataEmployeesPanel");
			this.setTitle("基础数据管理--员工管理");
			Util.setButtonStatus(toolBar,dataEmployeesButton);
			SwingUtilities.invokeLater(dataEmployeesPanel);
		}else if(e.getSource()==dataStorageButton){
			//仓库管理按钮
			dataStoragePanel = new DataStoragePanel();
			main.add(dataStoragePanel,"dataStoragePanel");
			main_layout.show(main, "dataStoragePanel");
			this.setTitle("基础数据管理--仓库管理");
			Util.setButtonStatus(toolBar,dataStorageButton);
			SwingUtilities.invokeLater(dataStoragePanel);
		}else if(e.getSource()==dataVendorButton){
			//供应商管理按钮
			dataVendorPanel = new DataSupplierPanel();
			main.add(dataVendorPanel,"dataVendorPanel");
			main_layout.show(main, "dataVendorPanel");
			this.setTitle("基础数据管理--供应商管理");
			Util.setButtonStatus(toolBar,dataVendorButton);
			SwingUtilities.invokeLater(dataVendorPanel);
		}else if(e.getSource()==dataShopButton){
			//商店管理
			dataShopPanel = new DataShopPanel();
			main.add(dataShopPanel,"dataShopPanel");
			main_layout.show(main, "dataShopPanel");
			this.setTitle("基础数据管理--商店管理");
			Util.setButtonStatus(toolBar,dataShopButton);
			SwingUtilities.invokeLater(dataShopPanel);
		}else if(e.getSource()==cabinetButton){
			//商柜管理
			cabinetPanel = new CabinetPanel();
			main.add(cabinetPanel,"cabinetPanel");
			main_layout.show(main, "cabinetPanel");
			this.setTitle("基础数据管理--商柜管理");
			Util.setButtonStatus(toolBar,cabinetButton);
			SwingUtilities.invokeLater(cabinetPanel);
		}
		main.updateUI();
	}
	
	public void showButton(){
		if (toolBar != null && toolBar.getComponentCount() != 0)
			((JButton)toolBar.getComponent(0)).doClick();
	}
	
	public void showButton(int type) {
			switch(type){
			case 1:{dataCommodityButton.doClick();break;}
			case 2:{dataEmployeesButton.doClick();break;}
			case 3:{dataStorageButton.doClick();break;}
			case 4:{dataVendorButton.doClick();break;}
			case 5:{dataShopButton.doClick();break;}
			case 6:{cabinetButton.doClick();break;}
		}
	}
}
